package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.exception.BaseException;
import com.zzyl.exception.GlobalExceptionHandler;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingPlanController
 * @Author LiShunSen
 * @Date 2024-08-27
 */
@Slf4j
@RestController
@Api(tags = "护理计划相关接口")
@RequestMapping("/nursing/plan")
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> getPlan() {
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.getPlan();
        return success(nursingPlanVos);
    }

    /**
     * 新增护理计划
     *
     * @param nursingPlanDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult addPlan(
            @ApiParam(value = "护理计划数据" ,required = true)
            @RequestBody NursingPlanDto nursingPlanDto) {

            nursingPlanService.addPlan(nursingPlanDto);
            return success();

    }

    /**
     * 分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage(
            @ApiParam(value = "护理计划名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态:0-禁用,1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {

        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.getByPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingPlanVo> getId(@PathVariable("id") Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getId(id);
        return success(nursingPlanVo);
    }

    /**
     * 修改
     *
     * @param nursingPlanDto
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult updatePlan(
            @ApiParam(value = "修改的实体类")
            @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.updatePlan(nursingPlanDto);
        return success();
    }

    /**
     * 删除护理计划
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult deletePlan(@PathVariable("id") Long id){
        nursingPlanService.deletePlan(id);
        return success();
    }

    /**
     * 启用/禁用护理计划
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理计划")
    public ResponseResult statusPlan(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        nursingPlanService.statusPlan(id, status);
        return success();
    }
}
